<?php 

namespace Admin\Model;
use Think\Model;

/**
 * Class CountryModel
 * 国家管理模型
 *
 * @package Admin\Model
 * @author janatian
 */
class CountryModel extends Model
{
    const CODE_ENABLED_ON = 1;
    const CODE_ENBALED_OFF = 0;

    protected $trueTableName = 'country';

    /**
     * @return string
     */
    public function getCacheKey()
    {
        return "country_abbr2_list";
    }

    /**
     * 获取或重建国家列表
     * @param bool|false $recreate
     * @return mixed
     */
    public function getAllGeoAbbr2($recreate = false)
    {
        $key = $this->getCacheKey();
        $all = S($key);
        if ($recreate)
        {
            $all = $this->where(['enabled'=>self::CODE_ENABLED_ON])->getField('abbr2', true);
            S($key, $all);
        }

        return $all;
    }
}
